﻿using LinqToTwitter;
using Sitecore.Data.Items;

namespace TweetFeed
{
	public static class Authentication
	{

		public const string ConsumerKeyField = "TF Consumer Key";
		public const string ConsumerSecretField = "TF Consumer Secret";
		public const string AccessTokenField = "TF Access Token";
		public const string AccessTokenSecretField = "TF Access Token Secret";
		public const string WidgetType = "TF Widget Type";
		public const string SearchTerm = "TF Term";
		public const string StatusCount = "TF Status Count";
		public const string ShowImage = "TF Show Profile Image";
		public const string Settings = "TF Settings";


		public static SingleUserAuthorizer GetSingleUserAuthorizer(Item settingsItem)
		{
			var auth = new SingleUserAuthorizer();

			if (settingsItem != null)
			{
				auth.Credentials = new SingleUserInMemoryCredentials
					                   {
						                   ConsumerKey = settingsItem[ConsumerKeyField],
						                   ConsumerSecret = settingsItem[ConsumerSecretField],
						                   TwitterAccessToken = settingsItem[AccessTokenField],
						                   TwitterAccessTokenSecret = settingsItem[AccessTokenSecretField]
					                   };

				return auth;
			}

			return null;
		}
	}
}
